home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-imgwch.adb < prev    next >
Text File  |  1996-01-30  |  3KB  |  75 lines

  1. -----------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                     S Y S T E M . I M G _ W C H A R                      --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.9 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.Img_Char; use System.Img_Char;
  27. with System.WCh_Con;  use System.WCh_Con;
  28. with System.WCh_WtS;  use System.Wch_WtS;
  29.  
  30. package body System.Img_WChar is
  31.  
  32.    --------------------------
  33.    -- Image_Wide_Character --
  34.    --------------------------
  35.  
  36.    function Image_Wide_Character
  37.      (V    : Wide_Character;
  38.       S    : access String;
  39.       EM   : WC_Encoding_Method)
  40.       return Natural
  41.    is
  42.       Val : constant Natural := Wide_Character'Pos (V);
  43.       WS  : Wide_String (1 .. 3);
  44.  
  45.    begin
  46.       --  If in range of standard character, use standard character routine
  47.  
  48.       if Val < 16#80#
  49.         or else (Val <= 16#FF# and then EM = WCEM_Hex)
  50.       then
  51.          return Image_Character (Character'Val (Val), S);
  52.  
  53.       --  Otherwise return an appropriate escape sequence (i.e. one matching
  54.       --  the convention implemented by Scn.Wide_Char). The easiest thing is
  55.       --  to build a wide string for the result, and then use the Wide_Value
  56.       --  function to build the resulting String.
  57.  
  58.       else
  59.          WS (1) := ''';
  60.          WS (2) := V;
  61.          WS (3) := ''';
  62.  
  63.          declare
  64.             W : constant String := Wide_String_To_String (WS, EM);
  65.  
  66.          begin
  67.             S (1 .. W'Length) := W;
  68.             return W'Length;
  69.          end;
  70.       end if;
  71.  
  72.    end Image_Wide_Character;
  73.  
  74. end System.Img_WChar;
  75.